package com.dangdang.guava.io;

import java.io.*;
import java.util.Enumeration;
import java.util.Vector;


public class SequenceInputStreamDemo2 {

	private static final String dir="D:\\codes\\sharding-jdbc-demo\\src\\main\\java\\com\\dangdang\\guava\\io\\";
    public static void main(String[] args) throws IOException {
        // SequenceInputStream(Enumeration e)
        // 通过简单的回顾我们知道了Enumeration 是Vector 中的一个方法的返回值类型。
        // Enumeration<E> elements()
        Vector<InputStream> v = new Vector<InputStream>();
        InputStream s1 = new FileInputStream(dir+"a.txt");
        InputStream s2 = new FileInputStream(dir+"b.txt");
        InputStream s3 = new FileInputStream(dir+"c.txt");
        v.add(s1);
        v.add(s2);
        v.add(s3);
        Enumeration<InputStream> en = v.elements();
        SequenceInputStream sis = new SequenceInputStream(en);
        BufferedOutputStream bos = new BufferedOutputStream(
                new FileOutputStream(dir+"d.txt"));

        // 如何写读写呢，其实很简单，你就按照以前怎么读写，现在还是怎么读写
        byte[] bys = new byte[1024];
        int len = 0;
        while ((len = sis.read(bys)) != -1) {
            bos.write(bys, 0, len);
        }

        bos.close();
        sis.close();

    }

}